<<template>
  <div >
    <head-top head-title="月度线网重点指标" go-back='true'></head-top>     
     <el-table    :data='netKeyKpi'  element-loading-text='给我一点时间' border fit highlight-current-row>
        <el-table-column  label='线别'  fixed  prop="lineName" width="80" >
        </el-table-column>
        <el-table-column  label='指标名' prop="zbName" width="95">
        </el-table-column>
        <el-table-column  label='客运量' prop="sum_pass_trans" width="220">
        </el-table-column>
        <el-table-column  label='实际开行列次'   prop="sum_sjkx_mon" width="80" >
        </el-table-column>
        <el-table-column  label='兑现率' prop="yxtdx_avg" width="95">
        </el-table-column>
        <el-table-column  label='正点率' prop="lczdl_avg" width="95">
        </el-table-column>
        <el-table-column  label='运营里程'    prop="sum_yylc_mon" width="80" >
        </el-table-column>
        <el-table-column  label='列车服务可靠度' prop="fuwum" width="95">
        </el-table-column>
        <el-table-column  label='日均客运量' prop="pass_trans_per" width="95">
        </el-table-column>
        <el-table-column  label='平均运距'  prop="sum_aver_load" width="80" >
        </el-table-column>
        <el-table-column  label='单程票使用率' prop="singleUsePntMon" width="95">
        </el-table-column>
    </el-table> 
  </div>   
</template>
<script>
  import { fetchDetail} from "@/mob/dtarget";
  import headTop from "src/components/head";
  import { Cell } from 'vux';
  //import store from './store/index';
  import { Group } from 'vux';  
  import vue from "vue";
  export default{
    components:{
      headTop,Cell,Group
    },
    data() {
      return {
      listLoading: null,
      list: null,    
      total: null,      
      current: "",
      datei: "", 
      netKeyKpi:[],       
      date:undefined           
    };
    },
    created(){  
      this.datei= this.$route.query.date;//接收传过来的月份参数
      //console.log("this.datei", this.datei); 
      var dates=new  Date(); 
      //console.log("this.dates", dates); 
      var seperator1 = "-";
      var year = dates.getFullYear();
      // console.log("this.year", year); 
      var month = dates.getMonth() + 1;  
      //console.log("this.month", month); 
      var strDate = dates.getDate();   
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      this.current= year + seperator1 + month;//获取当前时间，时间格式为2018-06
     
              
      var datev=new  Date().getTime();
      var dayv= (datev)-60*60*24*1*1000;
      var datef=new Date(dayv); 
      var strDates = datef.getDate();
      if (strDates >= 0 && strDates <= 9) {
        strDates = "0" + strDates;
      }
     //测试用例
      //this.current= year +  seperator1  +"05";//获取当前时间，时间格式为2018-06
      //console.log("this.current", this.current);   
      //strDate="26";
      //console.log("strDate",strDate); 
      //var strDates="25"; 
      // console.log("strDates",strDates); 


      if(this.datei> this.current){ //如果传过来的日期参数大于现在的时间月份  
       // console.log("this.current1", this.current);        
        this.date= year + seperator1 + month + seperator1 + strDates;
       // console.log("this.date1",  this.date); 
      //获取昨天的日期，时间格式为2018-06-11
      }else if(this.datei==this.current){
        if(strDate>= 27){
          this.date= this.datei+ seperator1 +"25";//则获取的时间格式为传过来的时间参数+25
         // console.log("this.date2",  this.date); 
        }else{
          this.date= year + seperator1 + month + seperator1 + strDates;
          //console.log("this.date3",  this.date); 
        }
      }else{//如果传过来的时间参数小于当前实际月份        
        this.date= this.datei+ seperator1 +"25";//则获取的时间格式为传过来的时间参数+25
        //console.log("this.date4",  this.date); 
      }
      //console.log("this.date", this.date); 
      fetchDetail(this.date).then(response => { //通过时间参数去 fetchDetail中获取后台数据        
        console.log("response", response); 
        if (response.status === 200) {
          console.log("response.status", response.status); 
          console.log("response.data.content", response.data.content); 
         
          //转译 由于数据库提取的数据存在空白字符，冒号等情况，所以需要先进行转移去掉空白字符和冒号
          // var list = JSON.stringify(response.data.content).replace("\\n", "").replace("\\r", "").replace(/\"/g, "", ""); 
          //console.log("json_str",  JSON.stringify(response.data.content) );                      
          var list1 = response.data.content.replace(/\s/g,""); //去掉数据库数据的空白字符  
          //console.log("list1", list1);
          this.list = JSON.parse(list1);//将String类型转换为json格式
          //console.log("this.list", this.list);
          // console.log("this.list.netKeyKpi", this.list.netKeyKpi);
          this.netKeyKpi=this.list.netKeyKpi;//获取数据中的netKeyKpi数据                      
        } else {
         // console.log(response);
          this.$notify({
            title: "未找到数据，请确认日期",
            message: response.status + response.data.msg,
            type: "error",
            duration: 200000
          });
         }    
      });
    },
    methods: {     

  }
};
</script>